package week0302;

import java.util.Arrays;
import java.util.Scanner;


public class Main4{


    private static Scanner in;

    public static void main(String[] args) {
        in = new Scanner(System.in);
        while (true) {
            int n;
            n = in.nextInt();
            shape[] shapes = new shape[n];
            for (int i = 0; i < n; i++) {
                String str;
                str = in.next();
                if (str.equals("rect"))
                    shapes[i] = new Rectangle(in.nextInt(), in.nextInt());
                else if (str.equals("cir"))
                    shapes[i] = new Circle(in.nextInt());
            }
            System.out.println(sumAllPerimeter(shapes,n));
            System.out.println(sumAllArea(shapes,n));
            Arrays.sort(shapes);
            System.out.println(Arrays.deepToString(shapes));
            for (int i = 0; i < n; i++) {
                System.out.println(shapes[i].getClass()+","+shapes[i].getClass().getSuperclass());
            }

        }

    }

    public static double sumAllArea(shape[] shapes,int n){
        double add=0;
        for (int i = 0; i < n; i++) {
            add=add+shapes[i].getArea();
        }
        return add;
    }

    public static double sumAllPerimeter(shape[] shapes,int n)
    {
        double add=0;
        for (int i = 0; i < n; i++) {
            add=add+shapes[i].getPerimeter();
        }
        return add;
    }


}

abstract class shape implements Comparable<shape>{
    public abstract double getPerimeter();
    public abstract double getArea();
    public static final double PI=3.14;
	public abstract int compareTo(shape o);
    
}


class Rectangle extends shape{



    private int width;
    private int length;


    public Rectangle(int width,int length)
    {
        this.width=width;
        this.length=length;
    }

    public double getPerimeter()
    {
        return (width+length)*2;
    }

    public double getArea(){
        return width*length;
    }

    @Override
    public String toString() {
        return "Rectangle [width=" + width + ", length=" + length + "]";
    }

	@Override
	public int compareTo(shape o) {
		// TODO Auto-generated method stub
		return Double.compare(this.getArea(), o.getArea());
	}




}

class Circle extends shape{
    private int radius;

    public Circle(int radius)
    {
        this.radius=radius;
    }

    public double getPerimeter()
    {
        return PI*2*radius ;
    }

    public double getArea(){
        return PI*radius*radius;
    }

    @Override
    public String toString() {
        return "Circle [radius=" + radius + "]";
    }

	@Override
	public int compareTo(shape o) {
		// TODO Auto-generated method stub
		return Double.compare(this.getArea(), o.getArea());
	}

    

}